package cn.kshost.zqyg.product.controller;

import cn.kshost.zqyg.model.dto.product.ProductDto;
import cn.kshost.zqyg.model.dto.product.SkuSaleDto;
import cn.kshost.zqyg.model.entity.product.Product;
import cn.kshost.zqyg.model.entity.product.ProductSku;
import cn.kshost.zqyg.model.vo.common.Result;
import cn.kshost.zqyg.model.vo.common.ResultCodeEnum;
import cn.kshost.zqyg.model.vo.h5.ProductItemVo;
import cn.kshost.zqyg.product.service.ProductService;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/product")
public class ProductController {

    @Autowired
    ProductService productService;



    @RequestMapping("/{page}/{limit}")
    public Result getProductSku(@PathVariable Integer page, @PathVariable Integer limit, ProductDto productDto) {
         PageInfo<ProductSku> productSkuPageInfo =  productService.getProductList(page,limit,productDto);
         return Result.build(productSkuPageInfo, ResultCodeEnum.SUCCESS);
    }

    @RequestMapping("/item/{skuId}")
    public Result<ProductItemVo> getProductItemDetailBySkuId(@PathVariable Integer skuId) {

        ProductItemVo ProductItemVo =  productService.getProductItemDetailBySkuId(skuId);
        return  Result.build(ProductItemVo, ResultCodeEnum.SUCCESS);
    }
    @Operation(summary = "通过商品id查询商品数据")
    @GetMapping("/getBySkuId/{skuId}")
    public Result<ProductSku> getProductBySkuId(@PathVariable(name = "skuId") Long skuId) {
        ProductSku productSku =  productService.getProductskuByid(skuId);
        return Result.build(productSku, ResultCodeEnum.SUCCESS);

    }
    @Operation(summary = "更新商品销量和库存")
    @PostMapping("/updateSkuSaleNum")
    Boolean updateSkuSaleNumAndStock(@RequestBody List<SkuSaleDto> skuSaleDtos){
       return productService.updateSkuSaleNumAndStock(skuSaleDtos);
    }
}
